<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body onload="document.getElementById('form1:codigo').focus()">
        <ui:composition template="templateTeste.xhtml">
            <ui:define name="centro">
                <p:messages globalOnly="true" showDetail="true"/>
                <!--h2><h:messages globalOnly="true" layout="table" showDetail="true" infoStyle="color: blue" warnStyle="color: yellow" errorStyle="color: red"/></h2-->
                
                <h:form id="form1">
                    <h:outputText value="#{mens.PRODUTO}" style="margin-left: 10px" styleClass="outputText"/>
                    <h:selectOneMenu id="produto" value="#{manterVendaBean.produto.id}">
                        <f:selectItems value="#{manterVendaBean.listaProduto}" var="produto" itemLabel="#{produto.nome}" itemValue="#{produto.id}"/>
                    </h:selectOneMenu>
                    <br/>
                    
                    <h:outputText value="#{mens.CLIENTE}" style="margin-left: 10px" styleClass="outputText"/>
                    <h:selectOneMenu id="cliente" value="#{manterVendaBean.cliente.codigo}">
                        <f:selectItems value="#{manterVendaBean.listaClientes}" var="cliente" itemLabel="#{cliente.nome}" itemValue="#{cliente.codigo}"/>
                    </h:selectOneMenu>
                    <br/>

                    
                      
                    <br/><br/>

                    <h:outputText value="#{mens.QUANTIDADE}" style="margin-left: 20px" styleClass="outputText"/>
                    <p:inputText id="quantidade" required="true" value="#{manterVendaBean.quantidade}" size="30" >
                        <f:validateRegex pattern="[0-9]*" for="quantidade" />
                    </p:inputText>
                    <p:message for="quantidade"/>
                    <br/>

                    <h:outputText value="#{mens.VALOR}" style="margin-left: 20px" styleClass="outputText" rendered="#{manterVendaBean.finalizouAdicionar}"/>
                    <p:inputText id="vDinheiro" required="true" value="#{manterVendaBean.valorDinheiro}" size="30" rendered="#{manterVendaBean.finalizouAdicionar}">
                        <f:validateRegex pattern="[0-9_._,]*"/>
                        <f:validateLength  maximum="7" />
                    </p:inputText>
                    <p:message for="vDinheiro"/>
                    <br/>

                    <h:outputText value="#{mens.VALORCHEQUE}" style="margin-left: 20px" styleClass="outputText" rendered="#{manterVendaBean.finalizouAdicionar}"/>
                    <p:inputText id="vCheque" required="true" value="#{manterVendaBean.valorCheque}" size="30" rendered="#{manterVendaBean.finalizouAdicionar}" >
                        <f:validateRegex pattern="[0-9_._,]*"/>
                        <f:validateLength  maximum="7" />
                    </p:inputText>
                    <p:message for="vCheque"/>
                    <br/>

                    <h:outputText value="#{mens.DATA}" style="margin-left: 20px" styleClass="outputText" rendered="#{manterVendaBean.finalizouAdicionar}"/>
                    <p:calendar id="data" required="true" value="#{manterVendaBean.dataVenda}" size="30" navigator="true" rendered="#{manterVendaBean.finalizouAdicionar}"/>
                    <p:message for="data"/>
                    <br/>


                    <br/>
                    <h:commandButton value="#{mens.ADDITEMCOMPRA}" action="#{manterVendaBean.addItemVenda}"/>
                    <h:commandButton value="#{mens.FINALIZARADD}" action="#{manterVendaBean.finalizarAdicionarItens}" disabled="#{!manterVendaBean.existeItemAdd or manterVendaBean.finalizouAdicionar}"/>
                    <h:commandButton value="#{mens.INSERIR}" action="#{manterVendaBean.create}" style="margin-left: 30px" disabled="#{!manterVendaBean.existeItemAdd or !manterVendaBean.finalizouAdicionar}" />
                    

                </h:form>

                    <h:form>
                        <h:commandButton value="#{mens.ADICIONARNOVOSITENS}" action="#{manterVendaBean.adicionarNovosItens}" disabled="#{!manterCompraBean.finalizouAdicionar}"/>
                    <h:commandButton value="#{mens.PESQUISAR}" action="#{manterVendaBean.findVendaEntities}" />
                    <p:dataTable paginator="true" rows="4" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5" emptyMessage="#{mens.TABELA_VAZIA}" value="#{manterVendaBean.listaVendas}" var="vendas" style="width:620px " rendered="#{manterVendaBean.exibeTabela}">
                        <p:column style="width: 200px">

                            <f:facet name="header">Codigo</f:facet>
                            <h:outputText value="#{vendas.codigovenda}"/>

                        </p:column>

                        <p:column>
                            <f:facet name="header">Valor Cheque</f:facet>
                            <h:outputText value="#{vendas.valorCheque}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">Valor em Dinheiro</f:facet>
                            <h:outputText value="#{vendas.valorDinheiro}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">Valor Total</f:facet>
                            <h:outputText value="#{vendas.valorDinheiro + vendas.valorCheque}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">Data da Compra</f:facet>
                            <h:outputText value="#{vendas.dataVenda}"/>

                        </p:column>
                    </p:dataTable>
                </h:form>
                
                
            </ui:define>
        </ui:composition>
    </h:body>
</html>